<?php

namespace app\admin\controller;

use think\Db;
use think\Request;
use think\Exception;//事务处理
use admin\controller\Proitem;

class Album extends Auth
{
    public function __construct(Request $request){
        $this->getChildIDdata = [];
        parent::__construct($request);
        $this->data = $request->param();
        $this->user_id = session('userid') == null ? 1 : session('userid');
        $this->lang = isset($this->data['lang']) && $this->data['lang'] ? $this->data['lang'] : is_lang();
    }

    
    public function list()
    {   
        if(isset($this->data['request'])){
            if($this->data['request'] == 'list'){
                $where['del_at'] = 0; 
            }else{
                $where['del_at'] = ['neq',0]; 
            }
            if(isset($this->data['page']) && $this->data['page']){
                $page = $this->data['page'];
            }else{
                $page = 1;
                
            }

            if(isset($this->data['limit']) && $this->data['limit']){
                $limit = $this->data['limit'];
            }else{
                $limit = 1000000000;
            }

            $album = Db::name('album')->where($where)->order('create_at desc')->page($page,$limit)->select();
            foreach ($album as $k => $v) {
                $album[$k]['deankTime'] = $v['update_at'] > 0 ? $v['update_at'] : $v['create_at'];
                $album[$k]['share'] = $v['share'] == 1 ? 'O' : '-';
                $album[$k]['open_day'] = getTimeDates($v['open_day'],$this->lang,true);
                $album[$k]['finish_day'] = getTimeDates($v['finish_day'],$this->lang,true);
                $album[$k]['time'] = $v['create_at'] > 0 ? getTimeDates($v['create_at'],$this->lang) : getTimeDates($v['create_at'],$this->lang);
                $album[$k]['nickname'] = $v['update_id'] ? getinfo($v['update_id'], 'admin')['nickname'] : getinfo($v['create_id'], 'admin')['nickname'];//编辑者
            }

            $pageSum = Db::name('album')->count();
            return json_encode(array('status'=>1,'data'=>['data'=>$album,'pageSum'=>$pageSum,'page'=>$page]));
        }else{
            return view('list');
        }
    }

    // 添加
    public function albumopenAdd()
    {
        if(isset($this->data['request']) && $this->data['request'] == 'insert'){
            // dump($this->data);die;
            if(isset($this->data['name']) && $this->data['name']){
                $has_name = hasData('album',['title'=>$this->data['name']]);
                if($has_name) return json_encode(array('status'=>2,'msg'=>$this->data['name'].' '.lang('already_exists')));
                $insertAlbumData['title'] = $this->data['name'];
                $insertAlbumData['intro'] = $this->data['ins'];
                $insertAlbumData['share'] = $this->data['isSga'] == 'true' ? 1 : 0;
                // $insertAlbumData['pro']   = isset($this->data['Prochar']) ? count($this->data['Prochar']) : 0;
                $insertAlbumData['subtitle'] = $this->data['subtitle'];
                $insertAlbumData['open_day'] = strtotime($this->data['startTime']);
                $insertAlbumData['finish_day'] = strtotime($this->data['endTime']);
                $insertAlbumData['create_id'] = $this->user_id;
                $insertAlbumData['create_at'] = time();
                Db::startTrans();
                $insertAlbumDataId = insertData('album',$insertAlbumData);
                if($insertAlbumDataId){
                    if(isset($this->data['Prochar'])){
                        if(!empty($this->data['Prochar'])){
                            $proNum = 0;
                            foreach ($this->data['Prochar'] as $k => $v) {
                                $insertDetailData['pro_id'] = $v['pro_id'];
                                $insertDetailData['prochar_id'] = $v['prochar_id'];
                                // $insertDetailData['drank'] = $v['drank'];
                                $insertDetailData['drank'] = $k;
                                $insertDetailData['album_id'] = $insertAlbumDataId;
                                $insertDetailData['create_at'] = time();
                                $IsIsertDetailData = insertData('album_detail',$insertDetailData);
                                if($v['prochar_id'] != 0)
                                    $proNum += 1;
                                else
                                    $proNum += hasData('prochar',['pro_id'=>$v['pro_id'],'status'=>1]);
                            }
                            if($IsIsertDetailData){
                                $ress = updateData('album',['id'=>$insertAlbumDataId],['pro'=>$proNum]);
                                Db::commit();
                                return json_encode(array('status'=>1,'msg'=>$this->data['name'].' '.lang('added_successfully')));
                            }else{
                                Db::rollback();
                                return json_encode(array('status'=>0,'msg'=>$this->data['name'].' '.lang('add_failed')));
                            }
                        }else{
                            Db::commit();
                            return json_encode(array('status'=>1,'msg'=>$this->data['name'].' '.lang('edited_successfully')));
                        }
                    }else{
                        Db::commit();
                        return json_encode(array('status'=>1,'msg'=>$this->data['name'].' '.lang('added_successfully')));
                    }
                }else{
                    Db::rollback();
                    return json_encode(array('status'=>0,'msg'=>$this->data['name'].' '.lang('add_failed')));
                }
            
            }else{
                return json_encode(array('status'=>2,'msg'=>lang('improve_submission_data')));
            }
        }else if(isset($this->data['request']) && $this->data['request'] == 'getProcharInfo'){
            $requestdata = [];
            if(isset($this->data['pro_id']) && $this->data['pro_id']) $requestdata['pro_id'] = $this->data['pro_id'];
            if(isset($this->data['prochar_id']) && $this->data['prochar_id']) $requestdata['prochar_id'] = $this->data['prochar_id'];
            if(!empty($requestdata)){
                $returnData = $this->getProcharInfo($requestdata);
                return json_encode(array('status'=>1,'data'=>$returnData));
            }else{
                return json_encode(array('status'=>2,'data'=>"未懈怠参数"));
            }
            
        }else if(isset($this->data['request']) && $this->data['request'] == 'add'){
            return view('albumopen',['title'=>'添加新产品图册','requestType'=>'add','lang'=>$this->lang]);
        }else{
            // dump($this->proAddNewJump_itemAjax($this->data,$this->lang));die();
            return json_encode(array('status'=>1,'data'=>$this->proAddNewJump_itemAjax($this->data,$this->lang)));
        }
    }


    // 编辑
    public function albumopenEdit()
    {
        if(isset($this->data['request']) && $this->data['request'] == 'edit'){
            if(isset($this->data['id']) && $this->data['id']){
                $res = getDatas('album',['*'],['id'=>$this->data['id']]);
                
                if(!empty($res)){
                    $returnData['detail'] = $res[0];
                }
                $returnData['detail']['open_day'] = getTimeDates($returnData['detail']['open_day'],$this->lang);
                $returnData['detail']['finish_day'] = getTimeDates($returnData['detail']['finish_day'],$this->lang);


                $album_detail = getDatas('album_detail',['*'],['album_id'=>$this->data['id']],'drank asc');
                if(!empty($album_detail)){
                    foreach ($album_detail as $k => $v) {
                        $returnData['iconInfo'][$k] = $this->getProcharInfo($v)[0];
                    }
                }

                // dump($returnData);die;
                return json_encode(array('status'=>1,'data'=>$returnData));
            }else{
                return json_encode(array('status'=>2,'msg'=>'请求数据有误'));
            }
        /************分隔符**************/
        }else if(isset($this->data['request']) && $this->data['request'] == 'update'){
            // dump($this->data);die;
            if(isset($this->data['name']) && $this->data['name']){
                $has_name = hasData('album',['title'=>$this->data['name'],'id'=>['neq',$this->data['id']]]);
                if($has_name) return json_encode(array('status'=>2,'msg'=>$this->data['name'].' '.lang('already_exists')));

                $updateAlbumData['title'] = $this->data['name'];
                $updateAlbumData['subtitle'] = $this->data['subtitle'];
                $updateAlbumData['intro'] = $this->data['ins'];
                // $updateAlbumData['pro'] = isset($this->data['Prochar']) ? count($this->data['Prochar']) : 0;
                $updateAlbumData['share'] = $this->data['isSga'] == 'true' ? 1 : 0;
                $updateAlbumData['open_day'] = strtotime($this->data['startTime']);
                $updateAlbumData['finish_day'] = strtotime($this->data['endTime']);
                $updateAlbumData['update_id'] = $this->user_id;
                $updateAlbumData['update_at'] = time();
                Db::startTrans();
                $isUpdateAlbumData = updateData('album',['id'=>$this->data['id']],$updateAlbumData);
                if($isUpdateAlbumData){
                    if(isset($this->data['Prochar'])){
                        // 先删除原有的数据，再添加
                        $res = deleteData('album_detail',['album_id'=>$this->data['id']]);
                        if(!empty($this->data['Prochar'])){
                            $proNum = 0;
                            foreach ($this->data['Prochar'] as $k => $v) {
                                $updateDetailData['pro_id'] = $v['pro_id'];
                                $updateDetailData['prochar_id'] = $v['prochar_id'];
                                // $updateDetailData['drank'] = $v['drank'];
                                $updateDetailData['drank'] = $k+1;
                                $updateDetailData['album_id'] = $this->data['id'];
                                $IsIsertDetailData = insertData('album_detail',$updateDetailData);
                                if($v['prochar_id'] != 0)
                                    $proNum += 1;
                                else
                                    $proNum += hasData('prochar',['pro_id'=>$v['pro_id'],'status'=>1]);
                                
                            }
                            if($IsIsertDetailData){
                                $ress = updateData('album',['id'=>$this->data['id']],['pro'=>$proNum]);
                                Db::commit();
                                return json_encode(array('status'=>1,'msg'=>$this->data['name'].' '.lang('edited_successfully')));
                            }else{
                                Db::rollback();
                                return json_encode(array('status'=>0,'msg'=>$this->data['name'].' '.lang('edit_failed')));
                            }
                        }else{
                            Db::commit();
                            return json_encode(array('status'=>1,'msg'=>$this->data['name'].' '.lang('edited_successfully')));
                        }
                    }
                }else{
                    Db::rollback();
                    return json_encode(array('status'=>0,'msg'=>$this->data['name'].' '.lang('edit_failed')));
                }
            }else{
                return json_encode(array('status'=>2,'msg'=>lang('improve_submission_data')));
            }
        }else if(isset($this->data['request']) && $this->data['request'] == 'requestEdit'){
            return view('albumopen',['title'=>'编辑新产品图册','requestType'=>'edit','id'=>$this->data['id'],'lang'=>$this->lang]);

        }else if(isset($this->data['request']) && $this->data['request'] == 'getProcharInfo'){
            $requestdata = [];
            if(isset($this->data['pro_id']) && $this->data['pro_id']) $requestdata['pro_id'] = $this->data['pro_id'];
            if(isset($this->data['prochar_id']) && $this->data['prochar_id']) $requestdata['prochar_id'] = $this->data['prochar_id'];
            if(!empty($requestdata)){
                $returnData = $this->getProcharInfo($requestdata);
                return json_encode(array('status'=>1,'data'=>$returnData));
            }else{
                return json_encode(array('status'=>2,'msg'=>"未懈怠参数"));
            }
        }else{
            return json_encode(array('status'=>1,'data'=>$this->proAddNewJump_itemAjax($this->data,$this->lang)));
        }
    }


    // 根据产品ID  和产品角色ID  获取产品信息
    function getProcharInfo($data)
    {
        if(isset($data['pro_id']) && $data['pro_id']){
            if(isset($data['prochar_id']) && $data['prochar_id']){
                $join = [
                            ['pro p','zu.pro_id = p.id',"LEFT"],
                            ['multi_lang pm','p.mkey = pm.mkey',"LEFT"],
                            ['pro_brand b','p.brand_id = b.id',"LEFT"],
                        ];
                $res = getSearch('prochar','zu',['zu.model,zu.pro_id,zu.id prochar_id,pm.content pro_name,b.name brand_name'],['pm.lang'=>$this->lang,'zu.id'=>$data['prochar_id']],$join,'zu.id asc');

                $res[0]['isPro'] = false;
                $res[0]['prochar_num'] = 0;
                $res[0]['reserve'] = 1000;

                $res[0]['img_url'] = getImgUrl($data['pro_id'],48,'prochar',$data['prochar_id']);
            }else{
                $join = [
                            // ['prochar pc','zu.id = pc.pro_id',"LEFT"],
                            ['multi_lang pm','zu.mkey = pm.mkey',"LEFT"],
                            ['pro_brand b','zu.brand_id = b.id',"LEFT"],
                        ];
                $res = getSearch('pro','zu',['zu.id pro_id,zu.brand_id,pm.content pro_name,b.name brand_name'],['pm.lang'=>$this->lang,'zu.id'=>$data['pro_id']],$join,'zu.id asc');
                $res[0]['prochar_num'] = hasData('prochar',['pro_id'=>$data['pro_id']]);
                $res[0]['isPro'] = true;
                $res[0]['reserve'] = 0;
                $res[0]['model'] = '';
                $res[0]['prochar_id'] = 0;
                $res[0]['img_url'] = getImgUrl($data['pro_id'],48);
            }
            $res[0]['drank'] = isset($data['drank']) ? $data['drank'] : 0;
            $res[0]['brand_name'] = $res[0]['brand_name'] !== null? $res[0]['drank'] : '';
            // dump($res);die;
            return $res;
        }
    }


    public function proAddNewJump_itemAjax($data,$lang){
        if(isset($data['request']) && $data['request'] == 'pro'){
            $pro2cate = getDatas('pro2cate',['*'],['procat_id'=>$data['cat_id']]);
            $prolist = [];
            if(!empty($pro2cate)){
                foreach ($pro2cate as $k => $v) {
                    if(isset($data['pro_id']) && $v['pro_id'] != $data['pro_id']){
                        $result = getMultiLangName('pro',['*'],['id'=>$v['pro_id']],'id asc');
                        if(!empty($result)) $prolist[] = $result[0];
                        
                    }
                    else{
                        $result = getMultiLangName('pro',['*'],['id'=>$v['pro_id']],'id asc');
                        if(!empty($result)) $prolist[] = $result[0];
                    }
                }
            }else{
                $prolist  = [];
            }
            foreach ($prolist as $k1 => $v1) {
                $prolist[$k1]['isPro'] = true;
            }
            // dump($prolist);die;
            return $prolist;

        }elseif (isset($data['request']) && $data['request']  == 'prochar') {
            $prochar = getDatas('prochar',['*'],['pro_id'=>$data['id']]);
            if(!empty($prochar)){
                foreach ($prochar as $k => $v) {
                    
                    $getLanguage = getLanguage($this->lang);
                    foreach ($getLanguage as $keygetLanguage => $valuegetLanguage) {
                        $returnFeatures['content_'.$valuegetLanguage['code']] = '';
                    }
                    // $$returnFeatures['content_'.$valuegetLanguage['code']] = rtrim($returnFeatures['content_'.$valuegetLanguage['code']],' / ');
                    $prochar2feature = getDatas('profeature2char',['*'],['prochar_id'=>$v['id']]);
                    if(!empty($prochar2feature)){
                        foreach ($prochar2feature as $k1 => $v1) {
                            $feature = getMultiLangName('proattr_value',['*'],['id'=>$v1['profeature_value_id']],'id asc')[0];
                            foreach ($returnFeatures as $keyreturnFeature => $valuereturnFeature) {
                                if(isset($feature['name_'.$this->lang])) $returnFeatures[$keyreturnFeature] = $valuereturnFeature . $feature['name_'.$this->lang] == '' ? '' : $feature['name_'.$this->lang].' / ';
                            }
                        }
                        foreach ($returnFeatures as $krtrim => $vrtrim) {    
                            $returnFeatures[$krtrim] = rtrim($returnFeatures[$krtrim],' / ');
                        }
                    }
                    
                    $returnFeatures['id'] =  $v['id'];
                    $returnFeature[$k] = $returnFeatures;
                    $returnFeature[$k]['pro_name'] = getValue('multi_lang',['mkey'=>'pro_'.$v['pro_id'],'lang'=>$this->lang],'content');
                    $returnFeature[$k]['model'] = $v['model'];
                    $brand_name = getSearch('pro','zu',['b.name'],['zu.id'=>$v['pro_id']],[['pro_brand b','zu.brand_id = b.id']],'zu.id desc');
                    if(!empty($brand_name)) $returnFeature[$k]['brand_name'] = $brand_name['0']['name'];
                    

                    $returnFeature[$k]['isCheck'] = false;
                    if(isset($data['prochar_id']) && $data['prochar_id']){
                        if($data['prochar_id'] == $v['id']){
                            $returnFeature[$k]['isCheck'] = true;
                        }else{
                            $returnFeature[$k]['isCheck'] = false;
                        }
                    }
                }
            }else{
                $returnFeature=[];
            }
            return $returnFeature;

        }else if(isset($data['request']) && $data['request']  == 'searchText'){
            if(isset($data['searchText']) && $data['searchText']){
                $join  = [
                            ['multi_lang mu','zu.mkey = mu.mkey'],
                            ['prochar p','zu.id = p.pro_id'],
                        ];
                // $field = ['zu.*,mu.content,p.id prochar_id,p.model'];
                $field = ['zu.*,mu.content'];
                $where['mu.lang'] = $lang;
                if(isset($data['pro_id'])){
                    $where['zu.id'] = ['not in',$data['pro_id']];
                }
                
                // 查找
                $where['zu.id|mu.content|p.model'] = ['like',"%".$data['searchText'].'%'];  
                $where['zu.is_item'] = 0;
                $productList = getSearch('pro','zu',$field,$where,$join,'zu.id desc');
                $productList = array_values(array_unique($productList,SORT_REGULAR ));
                if(!empty($productList)){

                    foreach ($productList as $k => $v) {

                        $pro_multi = getDatas('multi_lang',['*'],['mkey'=>'pro_'.$v['id']]);
                        foreach ($pro_multi as $k1 => $v1) {
                            $productList[$k]['name_'.$v1['lang']] = $v1['content'];
                        }
                        // $n=mb_stripos($v['model'],$data['searchText']);
                        // if($n === false){
                            $productList[$k]['isPro'] = true;
                        // }else{
                        //     $productList[$k]['isPro'] = false;
                        //     $profeature2char = getDatas('profeature2char',['profeature_value_id'],['prochar_id'=>$v['prochar_id']]);
                        //     $productList[$k]['featureName'] = '';
                        //     if(!empty($profeature2char)){
                        //         foreach ($profeature2char as $k1 => $v1) {
                        //             $productList[$k]['featureName'] .= getValue('multi_lang',['mkey'=>'proattr_value_'.$v1['profeature_value_id'],'lang'=>$lang],'content').' / ';
                        //         }
                        //     }
                        //     $productList[$k]['featureName'] = rtrim($productList[$k]['featureName'],' / ');
                        // }

                    }
                    return $productList;
                }else{
                    return $productList = [];
                }
            }else{
                return lang('no_data');
            }
        }
    }



    //  软删除数据恢复
    public function requestRestore()
    {
        if(isset($this->data['id']) && $this->data['id']){
            $restore['del_id'] = 0;
            $restore['del_at'] = 0;
            $title = getValue('album',['id'=>$this->data['id']],'title');
            if($title){
                $res = updateData('album',['id'=>$this->data['id']],$restore);
                if($res){
                    return json_encode(array('status'=>1,'msg'=>$title.lang('recovery_successful')));
                }else{
                    return json_encode(array('status'=>0,'msg'=>$title.lang('recovery_failed')));
                }
            }else{
                return json_encode(array('status'=>0,'msg'=>lang('recovery_failed').'数据为空'));
            }
        }else{
            return json_encode(array('status'=>2,'msg'=>lang('recovery_failed').'数据为空'));
        }
    }


    //  软删除数据批量恢复
    public function requestBatchRestore()
    {   
        $aa = new Proitem();
        $aa->proAddNewJump_itemAjax();
        if(isset($this->data['ids']) && $this->data['ids']){
            $batchRestore['del_id'] = 0;
            $batchRestore['del_at'] = 0;
            $idArr = explode(',', $this->data['ids']);
            $title = '';
            foreach ($idArr as $k => $v) {
                $title .= getValue('album',['id'=>$v],'title').'/';
                $res = updateData('album',['id'=>$v],$batchRestore);
            }
            $title = rtrim($title,'/');
            if($res){
                return json_encode(array('status'=>1,'msg'=>$title.lang('recovery_successful')));
            }else{
                return json_encode(array('status'=>0,'msg'=>$title.lang('recovery_failed')));
            }
        }else{
            return json_encode(array('status'=>2,'msg'=>lang('recovery_failed').'数据为空'));
        }
    }


    //  软删除数据清除
    public function requestDel()
    {
        if(isset($this->data['id']) && $this->data['id']){
            $title = getValue('album',['id'=>$this->data['id']],'title');
            if($title){
                $res = deleteData('album',['id'=>$this->data['id']]);
                if($res){
                    return json_encode(array('status'=>1,'msg'=>$title.lang('cleared_successfully')));
                }else{
                    return json_encode(array('status'=>0,'msg'=>$title.lang('clear_failed')));
                }
            }else{
                return json_encode(array('status'=>0,'msg'=>lang('clear_failed').'数据为空'));
            }
        }else{
            return json_encode(array('status'=>2,'msg'=>lang('clear_failed').'数据为空'));
        }
    }

    // 批量清除
    public function requestBatchClear()
    {
        if(isset($this->data['ids']) && $this->data['ids']){
            $idArr = explode(',', $this->data['ids']);
            $title = '';
            foreach ($idArr as $k => $v) {
                $title .= getValue('album',['id'=>$v],'title').'/';
                $res = deleteData('album',['id'=>$v]);
            }
            $title = rtrim($title,'/');
            if($res){
                return json_encode(array('status'=>1,'msg'=>$title.lang('cleared_successfully')));
            }else{
                return json_encode(array('status'=>0,'msg'=>$title.lang('clear_failed')));
            }
        }else{
            return json_encode(array('status'=>2,'msg'=>lang('clear_failed').'数据为空'));
        }
    }

    //  软删除数据
    public function requestSoftDelete()
    {
        if(isset($this->data['id']) && $this->data['id']){
            $softDelete['del_id'] = $this->user_id;
            $softDelete['del_at'] = time();
            $title = getValue('album',['id'=>$this->data['id']],'title');
            if($title){
                $res = updateData('album',['id'=>$this->data['id']],$softDelete);
                if($res){
                    return json_encode(array('status'=>1,'msg'=>$title.lang('deleted_successfully')));
                }else{
                    return json_encode(array('status'=>0,'msg'=>$title.lang('failed_to_delete')));
                }
            }else{
                return json_encode(array('status'=>0,'msg'=>lang('failed_to_delete').'数据为空'));
            }
        }else{
            return json_encode(array('status'=>2,'msg'=>lang('failed_to_delete').'数据为空'));
        }
    }

    
    // 批量删除
    public function requestBatchDelete()
    {
        if(isset($this->data['ids']) && $this->data['ids']){
            $softDelete['del_id'] = $this->user_id;
            $softDelete['del_at'] = time();
            $idArr = explode(',', $this->data['ids']);
            $title = '';
            foreach ($idArr as $k => $v) {
                $title .= getValue('album',['id'=>$v],'title').'/';
                $res = updateData('album',['id'=>$v],$softDelete);
            }
            $title = rtrim($title,'/');
            if($res){
                return json_encode(array('status'=>1,'msg'=>$title.lang('deleted_successfully')));
            }else{
                return json_encode(array('status'=>0,'msg'=>$title.lang('failed_to_delete')));
            }
        }else{
            return json_encode(array('status'=>2,'msg'=>lang('failed_to_delete').'数据为空'));
        }
    }


    //定价
    public function fixedPrice()
    {

        if(isset($this->data['album_id']) && $this->data['album_id']){
            if(isset($this->data['request']) && $this->data['request'] == 'requestAjax' ){
                
                $album_detail = getDatas('album_detail',['pro_id,prochar_id'],['album_id'=>$this->data['album_id']]);
                $priceData = model('Price')->getProPrice($album_detail,$this->lang,[]);

                return json_encode(array('status'=>1,'data'=>$priceData));
            }else{
                return view('price/list',['album_id'=>$this->data['album_id'],'viewType'=>'price']);
            }

        }
    }


    // album copy
    public function albumCopy()
    {
        if(isset($this->data['id']) && $this->data['id']){
            $albumCopy = getDatas('album',['title,subtitle,intro,pro,share,open_day,finish_day'],['id'=>$this->data['id']]);
            if(!empty($albumCopy))
            {   
                $album_detail = getDatas('album_detail',['*'],['album_id'=>$this->data['id']]);
                $albumCopy[0]['title'] = $albumCopy[0]['title'].' COPY';
                $albumCopy[0]['subtitle'] = $albumCopy[0]['subtitle'].' COPY';
                $albumCopy[0]['create_at'] = time();
                $albumCopy[0]['create_id'] = $this->user_id;
                $albumCopyId = insertData('album',$albumCopy[0]);

                if(!empty($album_detail)){
                    foreach ($album_detail as $k => $v) {
                        $v['album_id'] = $albumCopyId;
                        $v['create_at'] = time();
                        unset($v['id']);
                        $albumDetailCopy = insertData('album_detail',$v);
                    }
                    if($albumDetailCopy){
                        return json_encode(array('status'=>1,'msg'=>$albumCopy[0]['title'].lang('copy_added_successfully')));
                    }else{
                        return json_encode(array('status'=>0,'msg'=>$albumCopy[0]['title'].lang('copy_addition_failed')));
                    }
                }else{
                    if($albumCopyId) return json_encode(array('status'=>1,'msg'=>$albumCopy[0]['title'].lang('copy_added_successfully')));
                }
            }else{
                return json_encode(array('status'=>2,'msg'=>lang('no_data')));
            }
        }else{
            return json_encode(array('status'=>2,'msg'=>'请求数据有误'));
        }
    }

}